<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>好好鲜花后台登录页</title>

<meta
	content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
	name="viewport">

<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition login-page">
	<div class="login-box">
		<div class="login-logo">
			<a href="all-admin-index.html"><b>好好鲜花</b>后台管理系统</a>
		</div>
		<!-- /.login-logo -->
		<div class="login-box-body">
			<p class="login-box-msg">登录系统</p>

			<form id="loginForm" action="${pageContext.request.contextPath}/pages/main.jsp"
				method="post">
				<div class="form-group has-feedback">
					<input type="text" name="administratorname" class="form-control"
						placeholder="用户名" id="administratorname"> <span
						class="glyphicon glyphicon-envelope form-control-feedback"></span>
				</div>
				<div class="form-group has-feedback">
					<input type="password" name="password" class="form-control"
						placeholder="密码" id="password"> <span
						class="glyphicon glyphicon-lock form-control-feedback"></span>
				</div>
				<div class="row">
					<div class="col-xs-8">
						<div class="checkbox icheck">
							<label><input type="checkbox" id="autologin"> 记住账号和密码</label>
						</div>
					</div>
					<!-- /.col -->
					<div class="col-xs-4">
						<button type="button" class="btn btn-primary btn-block btn-flat" onclick="login()">登录</button>
					</div>
					<!-- /.col -->
				</div>
			</form>

			<a href="#" onclick="alert('请联系开发人员')">忘记密码</a><br>


		</div>
		<!-- /.login-box-body -->
	</div>
	<!-- /.login-box -->

	<!-- jQuery 2.2.3 -->
	<!-- Bootstrap 3.3.6 -->
	<!-- iCheck -->
	<script
		src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
	<script
		src="${pageContext.request.contextPath}/plugins/jQuery/jquery.cookie.js"></script>
	<script
		src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
	<script
		src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
	<script>
		$(function() {
			$('input').iCheck({
				checkboxClass : 'icheckbox_square-blue',
				radioClass : 'iradio_square-blue',
				increaseArea : '20%' // optional
			});
		});
	</script>
	
		<script type="text/javascript">
	$(document).ready(function () {
       if($.cookie('autologin')){
    	   $('#administratorname').val($.cookie('administratorname'));
           $('#password').val($.cookie('password')); 
       }
	  });
		function login() {
			if($("#administratorname").val() == ""){
				alert("请输入用户名");
				$("#administratorname").focus();
				return;
			}
			if($("#password").val() == ""){
				alert("请输入密码");
				$("#password").focus();
				return;
			}
			if($("#administratorname").val() != "" & $("#password").val() != ""){
				//检验用户名和密码是否正确
				$.get("${pageContext.request.contextPath}/administrator/login",{"administratorname":$("#administratorname").val(),"password":$("#password").val()},function(data){
					if(data.status){
						//提交表单
						var chk = $('#autologin')[0].checked;//被勾住就true
						if (chk) {
							 $.cookie('autologin', chk, {expires: 7});
							 $.cookie('administratorname', $('#administratorname').val(), {expires: 7});
							 $.cookie('password', $('#password').val(), {expires: 7});
							 $("#loginForm").submit();
							return;
						  } else {
							//如果没有选择；记住密码
							  $.cookie('autologin', chk);
							  $("#loginForm").submit();
							  return;
							}
						
					}
					alert("用户名或密码错误，请重新输入");
					return;
				});
			}
		}
			
	 
	</script>
</body>

</html>